package com.vipheyue.bigcompany.utils;

import android.app.Dialog;
import android.content.Context;
import android.os.CountDownTimer;
import android.support.v7.app.AlertDialog;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.vipheyue.bigcompany.R;


/**
 * Created by heyue on 2015/11/17.
 */
public class CustomDialog {

    public static Dialog onCreateDialog(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View linearlayout = inflater.inflate(R.layout.dialog_net, null);
        AlertDialog.Builder builder=   new AlertDialog.Builder(context);
        builder.setCancelable(false);
        final Dialog  dialog = builder.show();
        dialog.setContentView(linearlayout);// setcontentView 不是setview

        WindowManager m = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        Display d = m.getDefaultDisplay();  //为获取屏幕宽、高
        WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
//                params.width = (int) (d.getHeight() * 0.4);
//                params.height = (int) (d.getWidth() * 0.4);
        params.width = DensityUtil.dip2px(150);
        params.height = DensityUtil.dip2px(150);
        dialog.getWindow().setAttributes(params);//设置生效  dialog.show();一定要放在dialog.getWindow().setLayout(300, 200);的前面，否则不起作用。

        CountDownTimer cdt = new CountDownTimer(10*1000, 1000) {

			@Override
			public void onTick(long millisUntilFinished) {
			}

			@Override
			public void onFinish() {
                dialog.dismiss();
			}
		};
		cdt.start();

        return dialog;
    }

}
